package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.service.IStAppVersionService;
import com.ruoyi.system.api.service.impl.StAppVersionServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Api(tags="App版本信息")
@RestController
@RequestMapping("/api/cc/app/")
public class AppController extends BaseController {

    @Autowired
    private IStAppVersionService stAppVersionService;

    private static final Logger log = LoggerFactory.getLogger(AppController.class);

    /**
     *  获取APP最新发布版本信息
     *
     * @param
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020/4/5 4:10 下午
     */
    @GetMapping("latestApp")
    @ResponseBody
    @Authentication(tokenRequired = false, signRequired = false)
    @ApiOperation(value = "获取APP最新发布版本信息", httpMethod = "GET", notes = "获取APP最新发布版本信息")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData latestApp() {
       try {
          return stAppVersionService.latestApp();
       } catch (Exception e) {
           log.error("程序异常", e.getMessage());
           return new ResponseWithData().error().msg("系统异常！").code(500);
       }
    }

    /**
     *  根据版本号获取服务条款
     *
     * @param versionCode
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/4/5 4:21 下午
     */
    @GetMapping("termsOfService")
    @ResponseBody
    @Authentication(tokenRequired = false, signRequired = false)
    @ApiOperation(value = "根据版本号获取服务条款", httpMethod = "GET", notes = "根据版本号获取服务条款")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "版本号", name = "versionCode", required = true, dataType = "String", paramType = "query", example = "1")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> termsOfService(@RequestParam("versionCode") String versionCode){
        try {
            return stAppVersionService.termsOfService(versionCode);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常！").code(500);
        }
    }

}
